﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TangGuo.Resources;

namespace TangGuo.Resources
{
    static class PublicData
    {
        public static bool IsTangGuoSelect = false;
        public static bool IsTangGuoBlankSelect = false;
        public static bool LastSelectIsNumber=false;
        public static int TangGuoSelectedCol = 0;
        public static int TangGuoSelectedRow = 0;
        public static int TangGuoBlankSelectedCol = 0;
        public static int TangGuoBlankSelectedRow = 0;
    }
    public class BasePos
    {
        public int Col { get; set; }
        public int Row { get; set; }
        public int Number { get; set; }

        public BasePos() { }
        public BasePos(int col, int row)
        {
            Col = col;
            Row = row;
        }

        public bool IsSamePos(BasePos other)
        {
            if (other == null) return false;
            return other.Col == Col && other.Row == Row;
        }
        /// <summary>
        /// 判断一个位置是否是邻居
        /// </summary>
        /// <param name="pos">BasePos类实例</param>
        /// <returns></returns>
        public bool IsAdjacent(BasePos pos)
        {
            if (pos == null) return false;
            if (Col == pos.Col)
            {
                if (Math.Abs(Row - pos.Row) == 1) return true; // 上下相邻的两个点
            }
            if (Row == pos.Row)
            {
                if (Math.Abs(Col - pos.Col) == 1) return true; // 左右相邻的两个点
            }
            if (Row % 2 == 0)
            {
                if (Col - pos.Col == 1 && Math.Abs(Row - pos.Row) == 1) return true; // 偶数行，左侧上下两个点都是本点的邻居
            }
            if (Row % 2 == 1)
            {
                if (pos.Col - Col == 1 && Math.Abs(Row - pos.Row) == 1) return true; // 偶数行，右侧上下两个点都是本点的邻居
            }
            return false;
        }
    }

    public class AdjacentPos : BasePos
    {
        public BasePos LeftPos;
        public BasePos RightPos;
        public BasePos TopLeftPos;
        public BasePos TopRightPos;
        public BasePos BottomLeftPos;
        public BasePos BottomRightPos;
        public AdjacentPos()
        {
            LeftPos = null; RightPos = null; TopLeftPos = null; TopRightPos = null; BottomLeftPos = null; BottomRightPos = null;
        }
        /// <summary>
        /// 设置相邻位置列表
        /// </summary>
        public void SetAdjacentPos()
        {
            if (Col is 0 or 10 || Row is 0 or 10) { return; }
            LeftPos = new BasePos(Col - 1, Row);
            RightPos = new BasePos(Col + 1, Row);


            if (Row % 2 == 0) // 偶数行
            {
                TopLeftPos = new BasePos(Col - 1, Row - 1);
                BottomLeftPos = new BasePos(Col - 1, Row + 1);
                TopRightPos = new BasePos(Col, Row - 1);
                BottomRightPos = new BasePos(Col, Row + 1);
            }

            if (Row % 2 == 1)  // 奇数行
            {
                TopLeftPos = new BasePos(Col, Row - 1);
                BottomLeftPos = new BasePos(Col, Row + 1);
                TopRightPos = new BasePos(Col + 1, Row - 1);
                BottomRightPos = new BasePos(Col + 1, Row + 1);
            }
        }
        public BasePos GetAdjacentPos(int m)
        {
            return m switch
            {
                0 => LeftPos,
                1 => TopLeftPos,
                2 => TopRightPos,
                3 => BottomLeftPos,
                4 => BottomRightPos,
                5 => RightPos,
                _ => null,
            };
        }
    }


    public class Pos : AdjacentPos
    {

        public Pos() { }
        public Pos(int a, int b)
        {
            Col = a;
            Row = b;
            SetAdjacentPos();
        }

        public bool IsEmpty() { return Number == 0; }
        
    }



}
